<?xml version="1.0" encoding="CP850"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=CP850" http-equiv="Content-Type" />

  <title>Class: Tex</title>

  <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />

  <script src="./js/jquery.js" type="text/javascript" charset="utf-8"></script>
  <script src="./js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
  <script src="./js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
  <script src="./js/darkfish.js" type="text/javascript" charset="utf-8"></script>

</head>
<body id="top" class="class">

  <div id="metadata">
    <div id="home-metadata">
      <div id="home-section" class="section">
        <h3 class="section-header">
          <a href="./index.html">Home</a>
          <a href="./index.html#classes">Classes</a>
          <a href="./index.html#methods">Methods</a>
        </h3>
      </div>
    </div>

    <div id="file-metadata">
      <div id="file-list-section" class="section">
        <h3 class="section-header">In Files</h3>
        <div class="section-body">
          <ul>
          
            <li><a href="./lib/tex_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
              class="thickbox" title="lib/tex.rb">lib/tex.rb</a></li>
          
          </ul>
        </div>
      </div>

      
    </div>

    <div id="class-metadata">
      
      <!-- Parent Class -->
      <div id="parent-class-section" class="section">
        <h3 class="section-header">Parent</h3>
        
        <p class="link">Object</p>
        
      </div>
      

      

      

      
      <!-- Method Quickref -->
      <div id="method-list-section" class="section">
        <h3 class="section-header">Methods</h3>
        <ul class="link-list">
          
          <li><a href="#method-c-new">::new</a></li>
          
          <li><a href="#method-i-error">#error</a></li>
          
          <li><a href="#method-i-escape_char">#escape_char</a></li>
          
          <li><a href="#method-i-longtable">#longtable</a></li>
          
        </ul>
      </div>
      

      
    </div>

    <div id="project-metadata">
      
      
      <div id="fileindex-section" class="section project-section">
        <h3 class="section-header">Files</h3>
        <ul>
        
          <li class="file"><a href="./LICENSE.html">LICENSE</a></li>
        
          <li class="file"><a href="./README.html">README</a></li>
        
          <li class="file"><a href="./Rakefile.html">Rakefile</a></li>
        
          <li class="file"><a href="./nbproject/private/rake-d_txt.html">rake-d.txt</a></li>
        
        </ul>
      </div>
      

      <div id="classindex-section" class="section project-section">
        <h3 class="section-header">Class/Module Index
          <span class="search-toggle"><img src="./images/find.png"
            height="16" width="16" alt="[+]"
            title="show/hide quicksearch" /></span></h3>
        <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
        <fieldset>
          <legend>Quicksearch</legend>
          <input type="text" name="quicksearch" value=""
            class="quicksearch-field" />
        </fieldset>
        </form>

        <ul class="link-list">
        
          <li><a href="./Tex.html">Tex</a></li>
        
          <li><a href="./TexTest.html">TexTest</a></li>
        
        </ul>
        <div id="no-class-search-results" style="display: none;">No matching classes.</div>
      </div>

      
    </div>
  </div>

  <div id="documentation">
    <h1 class="class">Tex</h1>

    <div id="description" class="description">
      
    </div><!-- description -->

    
    <div id="5Buntitled-5D" class="documentation-section">
      

      

      

      
      <!-- Attributes -->
      <div id="attribute-method-details" class="method-section section">
        <h3 class="section-header">Attributes</h3>

        
        <div id="errors-attribute-method" class="method-detail">
          <a name="errors"></a>
          
          <a name="errors="></a>
          
          <div class="method-heading attribute-method-heading">
            <span class="method-name">errors</span><span
              class="attribute-access-type">[RW]</span>
          </div>

          <div class="method-description">
          
          
          
          </div>
        </div>
        
      </div><!-- attribute-method-details -->
      

      <!-- Methods -->
      
      <div id="public-class-method-details" class="method-section section">
        <h3 class="section-header">Public Class Methods</h3>

      
        <div id="new-method" class="method-detail ">
          <a name="method-c-new"></a>

          
          <div class="method-heading">
            <span class="method-name">new</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Initializing the class by setting the following variables:</p>
<dl><dt>errors</dt>
<dd>
<p>Array containing occuring errors</p>
</dd></dl>
            

            
            <div class="method-source-code" id="new-source">
<pre>
<span class="ruby-comment"># File lib/tex.rb, line 8</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>
   <span class="ruby-ivar">@errors</span> = []
<span class="ruby-keyword">end</span></pre>
            </div><!-- new-source -->
            
          </div>

          

          
        </div><!-- new-method -->

      
      </div><!-- public-class-method-details -->
    
      <div id="public-instance-method-details" class="method-section section">
        <h3 class="section-header">Public Instance Methods</h3>

      
        <div id="error-method" class="method-detail ">
          <a name="method-i-error"></a>

          
          <div class="method-heading">
            <span class="method-name">error</span><span
              class="method-args">(method, args, e)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Method covers occurring errors</p>

<p>The method requires the following arguments:</p>
<dl><dt>method</dt>
<dd>
<p>The object __method__</p>
</dd><dt>args</dt>
<dd>
<p>Array containing the argument passed to __method__</p>
</dd><dt>e</dt>
<dd>
<p>Exception containing the exception object</p>
</dd></dl>
            

            
            <div class="method-source-code" id="error-source">
<pre>
<span class="ruby-comment"># File lib/tex.rb, line 142</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">error</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">e</span>)
  <span class="ruby-identifier">error</span> = [<span class="ruby-string">&quot;Method   : &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">method</span>.<span class="ruby-identifier">to_s</span>,
           <span class="ruby-string">&quot;Parameter: &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">to_s</span>,
           <span class="ruby-string">&quot;Message  : &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>,
           <span class="ruby-string">&quot;Backtrace: &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;\n&quot;</span>)]
  <span class="ruby-ivar">@errors</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">error</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- error-source -->
            
          </div>

          

          
        </div><!-- error-method -->

      
        <div id="escape_char-method" class="method-detail ">
          <a name="method-i-escape_char"></a>

          
          <div class="method-heading">
            <span class="method-name">escape_char</span><span
              class="method-args">(str)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>LaTex Strings will be escaped</p>

<pre>Tex.escape_char(str) -&gt; string or self</pre>

<p>The method required the following arguments:</p>
<dl><dt>str</dt>
<dd>
<p>String in which all LaTex chars should be escaped</p>
</dd></dl>
            

            
            <div class="method-source-code" id="escape_char-source">
<pre>
<span class="ruby-comment"># File lib/tex.rb, line 123</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">escape_char</span>(<span class="ruby-identifier">str</span>) <span class="ruby-comment"># Raise an exception if *str* not a String</span>
  <span class="ruby-identifier">raise</span>(<span class="ruby-constant">TypeError</span>, <span class="ruby-node">&quot;Can't convert '#{str.class.name}' into String&quot;</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">str</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_str</span>)

  <span class="ruby-comment"># Define an array including all chars which should be escaped</span>
  <span class="ruby-identifier">chars</span> = <span class="ruby-node">]$ _ % &amp; # ~ \\]</span>

  <span class="ruby-comment"># Escape all chars in *self* which are equal to *chars*</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">union</span>(*<span class="ruby-identifier">chars</span>)) { <span class="ruby-string">&quot;\\&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-node">$&amp;</span> }
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">TypeError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">error</span>(<span class="ruby-identifier">__method__</span>, <span class="ruby-identifier">str</span>, <span class="ruby-identifier">e</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- escape_char-source -->
            
          </div>

          

          
        </div><!-- escape_char-method -->

      
        <div id="longtable-method" class="method-detail ">
          <a name="method-i-longtable"></a>

          
          <div class="method-heading">
            <span class="method-name">longtable</span><span
              class="method-args">(args, escape_char_header=false, escape_char_data=false)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Method returns a string containing the code for a longtable in LaTeX</p>

<pre>Tex.longtable(Hash, true, true) -&gt; string or nil</pre>

<p>The method requires as first argument a Hash including the following keys:</p>
<dl><dt>:caption</dt>
<dd>
<p>String containing the caption of the table.</p>
</dd><dt>:caption_toc</dt>
<dd>
<p>String containing the caption given in the list of tables</p>
</dd><dt>:col_def</dt>
<dd>
<p>Array contains the definition of the column types (e.g.: ['c', 'c', 'c']).</p>
</dd><dt>:header</dt>
<dd>
<p>Array containing the header for the table</p>
</dd><dt>:data</dt>
<dd>
<p>Array containing the data sets as arrays</p>
</dd></dl>

<p>The method processed optional a second and third argument:</p>
<dl><dt>escape_char_header</dt>
<dd>
<p>Boolean containing the information if LaTex chars in :header should be
escaped. Default value ist <b>false</b>.</p>
</dd><dt>escape_char_data</dt>
<dd>
<p>Boolean containing the information if LaTex chars in :data should be
escaped. Default value ist <b>false</b></p>
</dd></dl>

<h2>Example</h2>

<pre>tbl = Tex.new()
puts tbl.longtable({
  caption: &quot;This text will appear above the table&quot;,
  caption_toc: &quot;This text will appear in the table of contents&quot;,
  label = &quot;Tab001&quot;,
  col_def: ['c', 'c', 'c'],
  header: ['Column 1', 'A &amp; B', 'Column 3'],
  data: [[1,2,3], [4,'A &amp; B',5], [6,7,8]]
  }, true, true)</pre>
            

            
            <div class="method-source-code" id="longtable-source">
<pre>
<span class="ruby-comment"># File lib/tex.rb, line 39</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">longtable</span>(<span class="ruby-identifier">args</span>, <span class="ruby-identifier">escape_char_header</span>=<span class="ruby-keyword">false</span>, <span class="ruby-identifier">escape_char_data</span>=<span class="ruby-keyword">false</span>)

    <span class="ruby-comment"># Arguments to be checked</span>
    <span class="ruby-identifier">args_type</span> = {<span class="ruby-identifier">caption</span><span class="ruby-operator">:</span> [<span class="ruby-string">'String'</span>, <span class="ruby-string">'Required'</span>],
                 <span class="ruby-identifier">caption_toc</span><span class="ruby-operator">:</span> [<span class="ruby-string">'String'</span>, <span class="ruby-string">'Optional'</span>],
                 <span class="ruby-identifier">label</span><span class="ruby-operator">:</span> [<span class="ruby-string">'String'</span>, <span class="ruby-string">'Required'</span>],
                 <span class="ruby-identifier">col_def</span><span class="ruby-operator">:</span> [<span class="ruby-string">'Array'</span>, <span class="ruby-string">'Required'</span>],
                 <span class="ruby-identifier">header</span><span class="ruby-operator">:</span> [<span class="ruby-string">'Array'</span>, <span class="ruby-string">'Required'</span>],
                 <span class="ruby-identifier">data</span><span class="ruby-operator">:</span> [<span class="ruby-string">'Array'</span>, <span class="ruby-string">'Required'</span>]}

    <span class="ruby-comment"># Check if arguments are correct</span>
    <span class="ruby-identifier">correct_argument_class?</span>(<span class="ruby-identifier">args</span>, <span class="ruby-identifier">args_type</span>)

<span class="ruby-comment">#    # Required arguments given?</span>
<span class="ruby-comment">#    [:caption, :label, :col_def, :header, :data].each do |sym|</span>
<span class="ruby-comment">#      raise(ArgumentError, &quot;Argument '#{sym}' is required but not given!&quot;) unless args.include?(sym)</span>
<span class="ruby-comment">#    end</span>
<span class="ruby-comment">#</span>
<span class="ruby-comment">#    # Required arguments of the right instance?</span>
<span class="ruby-comment">#    [:header, :data, :col_def].each do |sym|</span>
<span class="ruby-comment">#      raise(ArgumentError, &quot;Argument '#{sym}' is of Type '#{args[sym].class.name}', but Array is required!&quot;) unless args[sym].instance_of?(Array)</span>
<span class="ruby-comment">#    end</span>
<span class="ruby-comment">#</span>
<span class="ruby-comment">#    # Required arguments of the right instance?</span>
<span class="ruby-comment">#    [:label, :caption, :caption_toc].each do |sym|</span>
<span class="ruby-comment">#      if args.include?(sym)</span>
<span class="ruby-comment">#        raise(ArgumentError, &quot;Argument '#{sym}' is of Type '#{args[sym].class.name}', but String is required!&quot;) unless args[sym].instance_of?(String)</span>
<span class="ruby-comment">#      end</span>
<span class="ruby-comment">#    end</span>
<span class="ruby-comment">#</span>
    <span class="ruby-identifier">raise</span>(<span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Number of columns in ':col_def' not equal with number of columns in ':header'!&quot;</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:col_def</span>].<span class="ruby-identifier">count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:header</span>].<span class="ruby-identifier">count</span>

    <span class="ruby-comment"># Generate the longtable LaTex code</span>
    <span class="ruby-identifier">tbl</span> = <span class="ruby-string">&quot;\\begingroup&quot;</span>
    <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\\centering\n&quot;</span>

    <span class="ruby-comment"># Add caption</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value">:caption_toc</span>) <span class="ruby-keyword">and</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:caption_toc</span>].<span class="ruby-identifier">empty?</span>
      <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;\\captionof{table}[#{args[:caption_toc]}]{#{args[:caption]}}\n&quot;</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;\\captionof{table}{#{args[:caption]}}\n&quot;</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># Begin of logtable</span>
    <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;\\label{#{args[:label]}}\n&quot;</span>
    <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;\\begin{longtable}{#{args[:col_def].join(' ')}}\n&quot;</span>
    <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\\toprule\n&quot;</span>


    <span class="ruby-comment"># If requested, escape LaTex chars in args[:header]</span>
    <span class="ruby-identifier">args</span>[<span class="ruby-value">:header</span>].<span class="ruby-identifier">map!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">escape_char</span> } <span class="ruby-keyword">if</span> <span class="ruby-identifier">escape_char_header</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">true</span>

    <span class="ruby-comment"># Join array to get an valid longtable row</span>
    <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:header</span>].<span class="ruby-identifier">join</span>(<span class="ruby-string">' &amp; '</span>) <span class="ruby-operator">+</span> <span class="ruby-string">&quot;\\tabularnewline\n&quot;</span>

    <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\\midrule\n&quot;</span>

    <span class="ruby-comment"># Insert longtable data rows</span>
    <span class="ruby-identifier">args</span>[<span class="ruby-value">:data</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>

      <span class="ruby-comment"># If requested, escape LaTex chars in args[:content][:data]</span>
      <span class="ruby-identifier">i</span>.<span class="ruby-identifier">map!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">escape_char</span> } <span class="ruby-keyword">if</span> <span class="ruby-identifier">escape_char_data</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">true</span>

      <span class="ruby-comment"># Join array to get an valid longtable row</span>
      <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">' &amp; '</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/&amp;\s*&amp;/</span>, <span class="ruby-string">'&amp; ~ &amp;'</span>) <span class="ruby-operator">+</span> <span class="ruby-string">&quot;\\tabularnewline\n&quot;</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># End of longtable</span>
    <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\\bottomrule\n&quot;</span>
    <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\\end{longtable}\n&quot;</span>
    <span class="ruby-identifier">tbl</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\\endgroup\n\n&quot;</span>

    <span class="ruby-keyword">return</span> <span class="ruby-identifier">tbl</span>
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">ArgumentError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">error</span>(<span class="ruby-identifier">__method__</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">e</span>)
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- longtable-source -->
            
          </div>

          

          
        </div><!-- longtable-method -->

      
      </div><!-- public-instance-method-details -->
    
    </div><!-- 5Buntitled-5D -->
  

  </div><!-- documentation -->

  <div id="validator-badges">
    <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
    <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
      Rdoc Generator</a> 2</small>.</p>
  </div>

</body>
</html>

